package com.thoughtworks.collection;

import org.apache.commons.collections.CollectionUtils;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class CollectionOperator {
    public List<Integer> getListByInterval(int left, int right) {
        Integer[] array=new Integer[5];
        if(left>right){
            for(int i=left;i>=right;i--){
                array[5-i]=i;
            }
        }else{
            for(int i=left-1;i<right;i++){
                array[i]=i+1;
            }
        }
        return Arrays.asList(array);
    }

    public List<Integer> getEvenListByIntervals(int left, int right) {
        List<Integer> list=new ArrayList<>();
        if(left>right) {
            for (int i = left; i >= right; i--) {
                    if (i % 2 == 0) {
                       list.add(i);
                    }
            }
        }else{
            for(int i=left;i<=right;i++){
                    if(i%2==0){
                        list.add(i);
                    }

            }
        }
        return list;
    }

    public List<Integer> popEvenElments(int[] array) {
        List<Integer> list=new ArrayList<>();
        for(int i=0;i<array.length;i++){
            if(array[i]%2==0){
                list.add(i+1);
            }
        }
        return  list;
    }

    public int popLastElment(int[] array) {
        int last;
        last=array[array.length-1];
        return last;
    }

    public List<Integer> popCommonElement(int[] firstArray, int[] secondArray) {
        List<Integer> list=new ArrayList<>();
        for (int i=0;i<firstArray.length;i++){
            for(int j=0;j<secondArray.length;j++){
                if(firstArray[i]==secondArray[j]){
                    list.add(firstArray[i]);
                }
            }
        }

        return list;
    }

    public List<Integer> addUncommonElement(Integer[] firstArray, Integer[] secondArray) {
        List<Integer> list = new ArrayList<>();
        for (int i=0;i<firstArray.length;i++){
            list.add(firstArray[i]);
        }
        List<Integer> list1 = Arrays.asList(firstArray);
        List<Integer> list2 = Arrays.asList(secondArray);
        list.addAll(CollectionUtils.subtract(list2, list1));
        return list;
    }
}
